Test Series - java script

Test Number 4/92

Q: What will be the output of the following JavaScript code?

var string1 = ”123”;
var intvalue = 123;
alert( string1 + intvalue );
A. 123246
B. 246
C. 123123
D. Exception
Solution: In JavaScript the alert function does the type casting and converts the integer value to string. After that it concatenates both the strings and shows the result as a concatenated string. Thus 123123 would be correct.
Q: A function definition expression can be called as __________
A. Function prototype
B. Function literal
C. Function calling
D. Function declaration
Solution: A function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” A Function definition expression typically consists of the keyword function followed by a comma-separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces.
Q: The property of a primary expression is ____________
A. stand-alone expressions
B. basic expressions containing all necessary functions
C. contains variable references alone
D. contains only keywords
Solution: The simplest expressions, known as primary expressions, are those that stand alone — they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain language keywords, and variable references.
Q: Consider the following JavaScript statements.

var text = "testing: 1, 2, 3"; // Sample text
var pattern = /d+/g // Matches all instances of one or more digits
In order to check if the pattern matches with the string “text”, the statement is ____________
A. text==pattern
B. text.equals(pattern)
C. text.test(pattern)
D. pattern.test(text)
Solution: The given pattern is applied on the text given in the parenthesis.
Q: The expression of calling (or executing) a function or method in JavaScript is called ________
A. Primary expression
B. Functional expression
C. Invocation expression
D. Property Access Expression
Solution: An invocation expression is JavaScript’s syntax for calling (or executing) a function or method). It starts with a function expression that identifies the function to be called.
Q: What kind of expression is “new Point(2,3)”?
A. Primary Expression
B. Object Creation Expression
C. Invocation Expression
D. Constructor Calling Expression
Solution: An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.
Q: Which of the operator is used to test if a particular property exists or not?
A. in
B. exist
C. within
D. exists
Solution: The operator “in” tests whether a particular property exists or not. In operator is usually added in looping statements to traverse the array or the object.
Q: Among the following, which one is a ternary operator?
A. +
B. :
C. 
D. ?:
Solution: JavaScript supports one ternary operator, the conditional operator ?:, which combines three expressions into a single expression. If else case can be replaced by the conditional operator
Q: “An expression that can legally appear on the left side of an assignment expression.” is a well known explanation for variables, properties of objects, and elements of arrays. They are called ___________
A. Properties
B. Prototypes
C. Lvalue
D. Definition
Solution: lvalue is a historical term that means “an expression that can legally appear on the left side of an assignment expression.” In JavaScript, variables, properties of objects, and elements of arrays are lvalues.
Q:  What will be the equivalent output of the following JavaScript code snippet?

x = ~-y;
w = x = y = z;
q = a?b:c?d:e?f:g;
A. x = ~(-y); w = (x = (y = z)); q = a?b:(c?d:(e?f:g));
B. x = a?b:(c?d:(e?f:g)); q = ~(-y); w = (x = (y = z));
C. x = (x = (y = z));w = ~(-y); q = a?b:(c?d:(e?f:g));
D. x = ~(-y); w = (x = (y = z)); q = (c?d:(e?f:g));
Solution: Brackets have higher precedence than any other operator. The placement of brackets results in the same result as without putting any bracket.

You Have Score    /10